import Vue from "vue";
import VueRouter from "vue-router";
// import login from '@/views/login.vue';//不能省略vue后缀
//登陆组件
import Login from "@/views/login.vue"; //如果文件夹里面是index.vue 可以省略不写
//注册组件
import Reg from "@/views/reg.vue"; //如果文件夹里面是index.vue 可以省略不写
import Home from "@/views/home.vue"; //如果文件夹里面是index.vue 可以省略不写
import appGoods from "@/views/appGoods.vue"; //如果文件夹里面是index.vue 可以省略不写
import appUsers from "@/views/appUsers.vue"; //如果文件夹里面是index.vue 可以省略不写
import appOrders from "@/views/appOrders.vue"; //如果文件夹里面是index.vue 可以省略不写

Vue.use(VueRouter);

const routes = [
	{
		path: "/",
		redirect: "/home",
	},
	{
		path: "/home",
		name: "home",
		redirect: "/home/users",
		component: Home,
		children: [
			{
				path: "goods",
				name: "goods",
				component: appGoods,
				meta: {
					//元信息
					permission: true, //需要拦截
					title: "商品管理",
				},
			},
			{
				path: "users",
				name: "users",
				component: appUsers,
				meta: {
					//元信息
					permission: true,
					title: "用户管理",
				},
			},
			{
				path: "orders",
				name: "orders",
				component: appOrders,
				meta: {
					//元信息
					permission: true,
					title: "订单管理",
				},
			},
		],
	},
	{
		path: "/login",
		name: "login",
		component: Login,
		meta: {
			//元信息
			permission: false, //不需要拦截
		},
	},
	{
		path: "/reg",
		name: "reg",
		component: Reg,
		meta: {
			//元信息
			permission: false, //不需要拦截
		},
	},
];
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch((err) => err);
};
const router = new VueRouter({
	mode: "history", //路由模式，默认是 hash
	routes,
});

export default router;
